using System;
using System.Globalization;
using HavardFjaer.Pushover.Client.Extensions;

namespace HavardFjaer.Pushover.Client
{
    public class PushoverMessageSender : PushoverClientBase
    {
        private const string MessageEndPoint = "https://api.pushover.net/1/messages.json";

        public PushoverMessageSender(string token, string user, ResponseFormat responseFormat) : base(token, user, MessageEndPoint, responseFormat)
        {
        }


        public string SendMessage(string message, string title = null, string device = null, string url = null, string urlTitle = null, MessagePriority priority = MessagePriority.Normal, DateTime? timestamp = null)
        {
            AddParameterIfNotNull("message", message);
            AddParameterIfNotNull("title", title);
            AddParameterIfNotNull("device", device);
            AddParameterIfNotNull("url", url);
            AddParameterIfNotNull("url_title", urlTitle);
            AddParameterIfNotNull("priority", ((int)priority).ToString(CultureInfo.InvariantCulture));
            if (timestamp.HasValue)
                AddParameterIfNotNull("timestamp", timestamp.Value.ConvertToUnixTimestamp().ToString(CultureInfo.InvariantCulture));
            return SendMessage();
        }
    }
}